#include "localxmlconfig.h"


LocalXMLConfig::LocalXMLConfig(FileDispatcher *dsp)
{
	dispatcher = dsp;
}

bool LocalXMLConfig::startElement(const QString &namespaceURI, const QString &localName,
								  const QString &qName, const QXmlAttributes &attributes)
{
	if (qName == "ftp_server")
	{
		QString v;
		dispatcher->files.clear();
		dispatcher->setURL(attributes.value("url"));
		dispatcher->setConfigFile(attributes.value("config_file"));
		dispatcher->setLogin(attributes.value("user"), attributes.value("password"));
		dispatcher->setTemporaryFolder(attributes.value("temporary_folder"));
		v = attributes.value("timeout");
		int t = 5;
		if (v.isEmpty())
		{
			bool ok;
			t = v.toInt(&ok);
			if (!ok || t <= 0) t = 5;
		}
		dispatcher->setConectionTimeout(t);
	}
	else if (qName == "file")
	{
		Version v;
		FTPFile *f = new FTPFile();
		f->setConfigName(attributes.value("config_name"));
		f->setLocalPath(attributes.value("local_path"));
		v = attributes.value("version");
		f->setOldVersion(v);
                f->setExecuteCommand(attributes.value("execute_command"));
		dispatcher->files.append(f);
	}
	return true;
}

bool LocalXMLConfig::endElement(const QString &namespaceURI, const QString &localName, const QString &qName)
{
	return true;
}

bool LocalXMLConfig::characters(const QString &str)
{
	return true;
}

bool LocalXMLConfig::fatalError(const QXmlParseException &exception)
{
	return false;
}
